"use strict";
// Class definition
var KStandard = function() {
    var baseTable;
    var scrollTable;
    var lockedLeftTable;
    var lockedBothTable;
    var eventHandler = function () {
        $('#alert-success').click(function(e) {
            KDatacom.alert({
                type: 'success',
                msg: '成功类·消息提示!'
            });
        });
        $('#alert-info').click(function(e) {
            KDatacom.alert({
                type: 'info',
                msg: '提示类·消息提示!'
            });
        });
        $('#alert-danger').click(function(e) {
            KDatacom.alert({
                type: 'danger',
                msg: '错误类·消息提示!'
            });
        });
        $('#alert-warning').click(function(e) {
            KDatacom.alert({
                type: 'warning',
                msg: '错误类·消息提示!'
            });
        });

        $('#swal-success').click(function(e) {
            KDatacom.swal({
                title: '成功！',
                text: "您的消息提交成功!",
                type: 'success',
            });
        });
        $('#swal-info').click(function(e) {
            KDatacom.swal({
                title: '提示！',
                text: "当前升级版本是0.0.1!",
                type: 'info'
            });
        });
        $('#swal-danger').click(function(e) {
            KDatacom.swal({
                title: '错误！',
                text: "您的消息提交失败!",
                type: 'error'
            });
        });
        $('#swal-warning').click(function(e) {
            KDatacom.swal({
                title: '警告！',
                text: "您没有当前操作的权限!",
                type: 'warning'
            });
        });
        $('#swal-question').click(function(e) {
            swal({
                title: '确认？',
                text: "您确定要删除这条数据吗？",
                type: 'question',
                showCancelButton: true
            }).then(function(result) {
                if (result.value) {
                    swal("成功！", "该条数据删除成功!", "success");
                }
            });
        });

        $(document).on('click', '.btn-search', doSearch);
        $(document).on('click', '.btn-search1', doSearch1);

        var $orgSelect = $('#org-select');
        $orgSelect.off('show.bs.modal');
        $orgSelect.on('show.bs.modal', initOrgSelectModal);

        var $staffSelect = $('#staff-select');
        $staffSelect.off('show.bs.modal');
        $staffSelect.on('show.bs.modal', initStaffSelectModal);
    };

    /**
     * 初始化组织树摸态框
     * @param e
     */
    var initOrgSelectModal = function (e) {
        var options = {};
        options.url = '../json/standard/org-tree.json';
        options.allowLevelIcons = ['operating_area', 'station', 'device'];
        options.relatedTarget = e.relatedTarget;

        /* 选中节点不关联其父子节点
        options.check = {
            chkboxType: { "Y": "", "N": "ps" }
        };
         */
        KOrgSelect.init(options);
    };

    /**
     * 初始化职员选择摸态框
     * @param e
     */
    function initStaffSelectModal(e) {
        var options = {};
        options.url = '../json/standard/staff-tree.json';
        options.allowLevelIcons = ['people'];
        options.relatedTarget = e.relatedTarget;

        /* 选中节点不关联其父子节点
        options.check = {
            chkboxType: { "Y": "", "N": "ps" }
        };
         */
        KStaffSelect.init(options);
    }

    var initSelectPicker = function () {
        $('.k_selectpicker').selectpicker();
    };

    var initDatePicker = function() {
        // 初始化日期选择器（注意必须设置format）
        $('#k_datepicker_1').datepicker({
            format: 'yyyy-mm-dd'
        });
        // 初始化日期选择器（注意必须设置format,带隐藏域）
        $('#k_datepicker_hide').datepicker({
            format: 'yyyy-mm-dd'
        });
        // 初始化日期 + 时间选择器
        $('#k_datetimepicker_1').datetimepicker();

        // 初始化日期 + 时间选择器（带隐藏域）
        $('#k_datetimepicker_2').datetimepicker();

        // 初始化时间选择器 变化最小单位（默认为1）
        $('#k_timepicker_1').timepicker({
            // minuteStep: 5
        });
        // 初始化时间选择器 禁用秒
        $('#k_timepicker_2').timepicker({
            showSeconds: false
        });
        // 初始化时间选择器 禁用上下午
        $('#k_timepicker_3').timepicker({
            showMeridian: false
        });
        // 初始化时间选择器（带隐藏域）
        $('#k_timepicker_hide').timepicker({});

        // 初始化日期范围选择器
        $('#k_daterangepicker_1').daterangepicker();

        // 初始化日期范围选择器
        $('#k_daterangepicker_hide').daterangepicker();

        // 初始化日期 + 时间 范围选择器
        $('#k_daterangepicker_2').daterangepicker({
            timePicker: true,
            locale: {
                format: 'YYYY-MM-DD HH:mm'
            }
        });

        // 初始化预选日期范围选择器
        var start = moment().subtract(29, 'days');
        var end = moment();
        $('#k_daterangepicker_3').daterangepicker({
            startDate: start,
            endDate: end,
            ranges: {
                '今天': [moment(), moment()],
                '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                '最近一周': [moment().subtract(6, 'days'), moment()],
                '最近30天': [moment().subtract(29, 'days'), moment()],
                '本月': [moment().startOf('month'), moment().endOf('month')],
                '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }
        });

        // 初始化起始日期(今天)范围选择器
        $('#k_daterangepicker_4').daterangepicker({
            minDate: moment()
        });

        // 初始化起始日期(上月到本月)范围选择器
        $('#k_daterangepicker_5').daterangepicker({
            minDate: moment().subtract(1, 'month').startOf('month'),
            maxDate: moment().endOf('month')
        });
        $('#k_daterangepicker_5').val('');
    };

    var initBaseTable = function () {
        baseTable = $('#base-table').KDatatable({
            // datasource definition
            data: {
                type: 'remote',
                source: {
                    read: {
                        url: '../json/standard/ajax-table.json',
                        method: 'GET'
                    },
                },
                pageSize: 10,
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true,
            },
            //
            // extensions: {
            //     checkbox: {},
            // },

            // layout definition
            layout: {
                scroll: false,
                footer: false,
            },

            // column sorting
            sortable: true,

            pagination: true,

            search: {
                input: $('#generalSearch'),
            },

            // columns definition
            columns: [
                {
                    field: 'checkbox',
                    title: '序号',
                    width: 30,
                    type: 'checkbox',
                    selector: {
                        class: 'k-checkbox k-checkbox--bold k-checkbox--accent'
                    },
                    textAlign: 'center',
                    template: function (row) {
                        return row.id;
                    },
                },
                {
                    field: 'id',
                    title: '序号',
                    width: 50,
                    type: 'number',
                    textAlign: 'center',
                }, {
                    field: 'employee_id',
                    title: 'Employee ID',
                }, {
                    field: 'name',
                    title: 'Name',
                    sortable: 'asc',
                    template: function (row) {
                        return row.first_name + ' ' + row.last_name;
                    },
                }, {
                    field: 'hire_date',
                    title: 'Hire Date',
                    hidden: true,
                    type: 'date',
                    format: 'MM/DD/YYYY',
                }, {
                    field: 'gender',
                    hidden: true,
                    title: 'Gender',
                }, {
                    field: 'status',
                    title: 'Status',
                    // callback function support for column rendering
                    template: function (row) {
                        var status = {
                            1: {'title': 'Pending', 'class': 'k-badge--brand'},
                            2: {'title': 'Delivered', 'class': ' k-badge--metal'},
                            3: {'title': 'Canceled', 'class': ' k-badge--primary'},
                            4: {'title': 'Success', 'class': ' k-badge--success'},
                            5: {'title': 'Info', 'class': ' k-badge--info'},
                            6: {'title': 'Danger', 'class': ' k-badge--danger'},
                            7: {'title': 'Warning', 'class': ' k-badge--warning'},
                        };
                        return '<span class="k-badge ' + status[row.status].class + ' k-badge--inline k-badge--pill">' + status[row.status].title + '</span>';
                    },
                }, {
                    field: 'type',
                    title: 'Type',
                    autoHide: false,
                    // callback function support for column rendering
                    template: function (row) {
                        var status = {
                            1: {'title': 'Online', 'state': 'danger'},
                            2: {'title': 'Retail', 'state': 'primary'},
                            3: {'title': 'Direct', 'state': 'accent'},
                        };
                        return '<span class="k-badge k-badge--' + status[row.type].state + ' k-badge--dot"></span>&nbsp;<span class="k-font-bold k-font-' + status[row.type].state + '">' +
                            status[row.type].title + '</span>';
                    },
                }, {
                    field: 'Actions',
                    title: '操作',
                    sortable: false,
                    width: 100,
                    overflow: 'visible',
                    textAlign: 'left',
                    autoHide: false,
                    template: function() {
                        return '\
							<div class="dropdown">\
								<a href="javascript:;" class="btn btn-sm btn-clean btn-icon btn-icon-md" data-toggle="dropdown">\
	                                <i class="la la-ellipsis-h"></i>\
	                            </a>\
							    <div class="dropdown-menu dropdown-menu-right">\
							        <a class="dropdown-item" href="#"><i class="la la-edit"></i> 编辑 详情</a>\
							        <a class="dropdown-item" href="#"><i class="la la-leaf"></i> 更新 状态</a>\
							        <a class="dropdown-item" href="#"><i class="la la-print"></i> 生成 报表</a>\
							    </div>\
							</div>\
							<a href="#">\
								编辑\
							</a>\
							<a href="#">\
								删除</i>\
							</a>\
						';
                    },
                }],

        });
        $('.bootstrap-select').selectpicker();
        baseTable.on('k-datatable--on-init', function() {
            var data = $(this).data('KDatatable').dataSet;
            data.forEach(function (item) {
                // 勾选符合条件的行。
                if (item.type === 2 || item.type === 3) {
                    baseTable.setActive(item.id.toString());
                }

                // 禁用符合条件的行的勾选
                if (item.status === 6 || item.status === 1) {
                    $(baseTable.tableBody).find('.k-checkbox--single').find('[type="checkbox"][value="' + item.id + '"]').prop('disabled', true)
                        .parent().addClass('k-checkbox--disabled').removeClass('k-checkbox--accent');
                }
            });
        });
    };

    var initScrollTable = function () {
        scrollTable = $('#scroll-table').KDatatable({
            data: {
                type: 'remote',
                source: {
                    read: {
                        url: '../json/standard/scroll-table.json',
                        method: 'GET'
                    }
                },
                pageSize: 10,
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },

            layout: {
                theme: 'default',
                class: '',
                scroll: true,
                footer: false
            },

            sortable: true,

            filterable: false,

            pagination: true,

            search: {
                input: $('#generalSearch1')
            },

            rows: {
                // disable responsive auto hide columns in row for horizontal scrollbar
                autoHide: false
            },

            columns: [
                {
                    field: 'id',
                    title: '序号',
                    width: 30,
                    type: 'number',
                    selector: false,
                    textAlign: 'center',
                }, {
                    field: 'employee_id',
                    title: '职员 ID',
                }, {
                    field: 'name',
                    sortable: 'asc',
                    title: 'Name',
                    template: function(row) {
                        return row.first_name + ' ' + row.last_name;
                    },
                }, {
                    field: 'email',
                    width: 150,
                    title: '邮件地址',
                }, {
                    field: 'phone',
                    title: '电话号码',
                }, {
                    field: 'hire_date',
                    title: '聘用日期',
                    type: 'date',
                    format: 'MM/DD/YYYY',
                }, {
                    field: 'gender',
                    title: '性别',
                }, {
                    field: 'notes',
                    title: '备注',
                    width: 300
                }, {
                    field: 'status',
                    title: '状态',
                    // callback function support for column rendering
                    template: function(row) {
                        var status = {
                            1: {'title': 'Pending', 'class': 'k-badge--brand'},
                            2: {'title': 'Delivered', 'class': ' k-badge--metal'},
                            3: {'title': 'Canceled', 'class': ' k-badge--primary'},
                            4: {'title': 'Success', 'class': ' k-badge--success'},
                            5: {'title': 'Info', 'class': ' k-badge--info'},
                            6: {'title': 'Danger', 'class': ' k-badge--danger'},
                            7: {'title': 'Warning', 'class': ' k-badge--warning'},
                        };
                        return '<span class="k-badge ' + status[row.status].class + ' k-badge--inline k-badge--pill">' + status[row.status].title + '</span>';
                    },
                }, {
                    field: 'type',
                    title: '类型',
                    autoHide: false,
                    // callback function support for column rendering
                    template: function(row) {
                        var status = {
                            1: {'title': 'Online', 'state': 'danger'},
                            2: {'title': 'Retail', 'state': 'primary'},
                            3: {'title': 'Direct', 'state': 'accent'},
                        };
                        return '<span class="k-badge k-badge--' + status[row.type].state + ' k-badge--dot"></span>&nbsp;<span class="k-font-bold k-font-' + status[row.type].state + '">' +
                            status[row.type].title + '</span>';
                    },
                }, {
                    field: 'Actions',
                    title: '操作',
                    sortable: false,
                    width: 100,
                    overflow: 'visible',
                    textAlign: 'left',
                    autoHide: false,
                    template: function() {
                        return '\
							<div class="dropdown">\
								<a href="javascript:;" class="btn btn-sm btn-clean btn-icon btn-icon-md" data-toggle="dropdown">\
	                                <i class="la la-ellipsis-h"></i>\
	                            </a>\
							    <div class="dropdown-menu dropdown-menu-right">\
							        <a class="dropdown-item" href="#"><i class="la la-edit"></i> 编辑 详情</a>\
							        <a class="dropdown-item" href="#"><i class="la la-leaf"></i> 更新 状态</a>\
							        <a class="dropdown-item" href="#"><i class="la la-print"></i> 生成 报表</a>\
							    </div>\
							</div>\
							<a href="#">\
								编辑\
							</a>\
							<a href="#">\
								删除</i>\
							</a>\
						';
                    },
                }],

        });
        $('.bootstrap-select').selectpicker();
    };

    var initLockedTable = function () {
        lockedLeftTable = $('#locked-left-table').KDatatable({
            data: {
                type: 'remote',
                source: {
                    read: {
                        url: '../json/standard/locked-table.json',
                        method: 'GET'
                    },
                },
                pageSize: 20,
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true,
            },

            layout: {
                theme: 'default',
                class: '',
                scroll: true,
                height: 550,
                footer: false,
            },

            sortable: false,

            filterable: false,

            pagination: true,

            search: {
                input: $('#generalSearch2'),
            },

            columns: [
                {
                    field: 'employee_id',
                    title: 'Employee ID',
                    locked: {left: 'lg'},
                }, {
                    field: 'name',
                    title: 'Name',
                    locked: {left: 'lg'},
                    template: function(row) {
                        return row.first_name + ' ' + row.last_name;
                    },
                }, {
                    field: 'email',
                    width: 150,
                    title: 'Email',
                }, {
                    field: 'phone',
                    title: 'Phone',
                }, {
                    field: 'hire_date',
                    title: 'Hire Date',
                    type: 'date',
                    format: 'MM/DD/YYYY',
                }, {
                    field: 'gender',
                    title: 'Gender',
                }, {
                    field: 'department',
                    title: 'Department',
                }, {
                    field: 'address',
                    title: 'Address',
                }, {
                    field: 'website',
                    title: 'Website',
                }, {
                    field: 'salary',
                    title: 'Salary',
                }, {
                    field: 'notes',
                    title: 'Notes',
                    width: 300,
                }, {
                    field: 'status',
                    title: 'Status',
                    // callback function support for column rendering
                    template: function(row) {
                        var status = {
                            1: {'title': 'Pending', 'class': 'k-badge--brand'},
                            2: {'title': 'Delivered', 'class': ' k-badge--metal'},
                            3: {'title': 'Canceled', 'class': ' k-badge--primary'},
                            4: {'title': 'Success', 'class': ' k-badge--success'},
                            5: {'title': 'Info', 'class': ' k-badge--info'},
                            6: {'title': 'Danger', 'class': ' k-badge--danger'},
                            7: {'title': 'Warning', 'class': ' k-badge--warning'},
                        };
                        return '<span class="k-badge ' + status[row.status].class + ' k-badge--inline k-badge--pill">' + status[row.status].title + '</span>';
                    },
                }, {
                    field: 'type',
                    title: 'Type',
                    autoHide: false,
                    // callback function support for column rendering
                    template: function(row) {
                        var status = {
                            1: {'title': 'Online', 'state': 'danger'},
                            2: {'title': 'Retail', 'state': 'primary'},
                            3: {'title': 'Direct', 'state': 'accent'},
                        };
                        return '<span class="k-badge k-badge--' + status[row.type].state + ' k-badge--dot"></span>&nbsp;<span class="k-font-bold k-font-' + status[row.type].state +
                            '">' +
                            status[row.type].title + '</span>';
                    },
                }, {
                    field: 'Actions',
                    title: 'Actions',
                    sortable: false,
                    width: 100,
                    overflow: 'visible',
                    textAlign: 'left',
                    autoHide: false,
                    template: function() {
                        return '\
							<div class="dropdown">\
								<a href="javascript:;" class="btn btn-sm btn-clean btn-icon btn-icon-md" data-toggle="dropdown">\
	                                <i class="la la-ellipsis-h"></i>\
	                            </a>\
							    <div class="dropdown-menu dropdown-menu-right">\
							        <a class="dropdown-item" href="#"><i class="la la-edit"></i> 编辑 详情</a>\
							        <a class="dropdown-item" href="#"><i class="la la-leaf"></i> 更新 状态</a>\
							        <a class="dropdown-item" href="#"><i class="la la-print"></i> 生成 报表</a>\
							    </div>\
							</div>\
							<a href="#">\
								编辑\
							</a>\
							<a href="#">\
								删除</i>\
							</a>\
						';
                    },
                }],
        });
        lockedBothTable = $('#locked-both-table').KDatatable({
            data: {
                type: 'remote',
                source: {
                    read: {
                        url: '../json/standard/locked-table.json',
                        method: 'GET'
                    },
                },
                pageSize: 20,
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true,
            },

            layout: {
                theme: 'default',
                class: '',
                scroll: true,
                height: 550,
                footer: false,
            },

            sortable: false,

            filterable: false,

            pagination: true,

            search: {
                input: $('#generalSearch3'),
            },

            columns: [
                {
                    field: 'employee_id',
                    title: 'Employee ID',
                    locked: {left: 'lg'},
                }, {
                    field: 'name',
                    title: 'Name',
                    locked: {left: 'lg'},
                    template: function(row) {
                        return row.first_name + ' ' + row.last_name;
                    },
                }, {
                    field: 'email',
                    width: 150,
                    title: 'Email',
                }, {
                    field: 'phone',
                    title: 'Phone',
                }, {
                    field: 'hire_date',
                    title: 'Hire Date',
                    type: 'date',
                    format: 'MM/DD/YYYY',
                }, {
                    field: 'gender',
                    title: 'Gender',
                }, {
                    field: 'department',
                    title: 'Department',
                }, {
                    field: 'address',
                    title: 'Address',
                }, {
                    field: 'website',
                    title: 'Website',
                }, {
                    field: 'salary',
                    title: 'Salary',
                }, {
                    field: 'notes',
                    title: 'Notes',
                    width: 300,
                }, {
                    field: 'status',
                    title: 'Status',
                    // callback function support for column rendering
                    template: function(row) {
                        var status = {
                            1: {'title': 'Pending', 'class': 'k-badge--brand'},
                            2: {'title': 'Delivered', 'class': ' k-badge--metal'},
                            3: {'title': 'Canceled', 'class': ' k-badge--primary'},
                            4: {'title': 'Success', 'class': ' k-badge--success'},
                            5: {'title': 'Info', 'class': ' k-badge--info'},
                            6: {'title': 'Danger', 'class': ' k-badge--danger'},
                            7: {'title': 'Warning', 'class': ' k-badge--warning'},
                        };
                        return '<span class="k-badge ' + status[row.status].class + ' k-badge--inline k-badge--pill">' + status[row.status].title + '</span>';
                    },
                }, {
                    field: 'type',
                    title: 'Type',
                    autoHide: false,
                    // callback function support for column rendering
                    template: function(row) {
                        var status = {
                            1: {'title': 'Online', 'state': 'danger'},
                            2: {'title': 'Retail', 'state': 'primary'},
                            3: {'title': 'Direct', 'state': 'accent'},
                        };
                        return '<span class="k-badge k-badge--' + status[row.type].state + ' k-badge--dot"></span>&nbsp;<span class="k-font-bold k-font-' + status[row.type].state + '">' +
                            status[row.type].title + '</span>';
                    },
                }, {
                    field: 'Actions',
                    title: '操作',
                    sortable: false,
                    width: 100,
                    overflow: 'visible',
                    textAlign: 'left',
                    locked: {right: 'lg'},
                    autoHide: false,
                    template: function() {
                        return '\
							<div class="dropdown">\
								<a href="javascript:;" class="btn btn-sm btn-clean btn-icon btn-icon-md" data-toggle="dropdown">\
	                                <i class="la la-ellipsis-h"></i>\
	                            </a>\
							    <div class="dropdown-menu dropdown-menu-right">\
							        <a class="dropdown-item" href="#"><i class="la la-edit"></i> 编辑 详情</a>\
							        <a class="dropdown-item" href="#"><i class="la la-leaf"></i> 更新 状态</a>\
							        <a class="dropdown-item" href="#"><i class="la la-print"></i> 生成 报表</a>\
							    </div>\
							</div>\
							<a href="#">\
								编辑\
							</a>\
							<a href="#">\
								删除</i>\
							</a>\
						';
                    },
                }],
        });
    };

    var initBaseForm = function () {
        $('#base-form .date-picker,#group-form .date-picker').datepicker({
            format: 'yyyy-mm-dd'
        });
        $('#base-form .datetime-picker,#group-form .datetime-picker').datetimepicker();
        $('#base-form .time-picker,#group-form .time-picker').timepicker();
        $('#base-form .daterange-picker,#group-form .daterange-picker').daterangepicker({
            timePicker: true,
            locale: {
                format: 'YYYY-MM-DD HH:mm'
            }
        });

        autosize($('textarea'));
    };

    var initValidation = function () {
        var baseValidator = $( "#base-form" ).validate({
            // define validation rules
            rules: {
                username: {
                    required: true
                },
                email: {
                    required: true,
                    email: true
                },
                date: {
                    required: true,
                    date: true
                },
                datetime: {
                    required: true
                },
                time: {
                    required: true
                },
                select: {
                    required: true,
                    minlength: 2,
                    maxlength: 4
                },
                checkbox: {
                    required: true
                },
                daterange: {
                    required: true
                },
                textarea: {
                    required: true
                },
                markdown: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: '请输入用户名!'
                },
                email: {
                    required: '请输入邮件地址!',
                    email: '请输入正确的邮件地址!'
                },
                date: {
                    required: '请选择日期!',
                    email: '请选择正确的日期!'
                },
                datetime: {
                    required: '请选择日期和时间!'
                },
                time: {
                    required: '请选择时间!'
                },
                select: {
                    required: '请选择下拉菜单!',
                    minlength: '至少选2个选项!',
                    maxlength: '最大选4个选项!'
                },
                checkbox: {
                    required: '请勾选复选框!'
                },
                daterange: {
                    required: '请选择日期范围!',
                    minlength: '请输入正确的邮件地址!'
                },
                textarea: {
                    required: '请输入备注!'
                },
                markdown: {
                    required: '请输入文本!'
                }
            },

            //display error alert on form submit
            invalidHandler: function(event, validator) {
                if (validator.errorList.length > 0) {
                    $(validator.errorList[0].element).focus();
                }
            },

            submitHandler: function (form) {
                form[0].submit(); // submit the form
            }
        });
        var groupValidator = $( "#group-form" ).validate({
            // define validation rules
            rules: {
                username: {
                    required: true
                },
                email: {
                    required: true,
                    email: true
                },
                date: {
                    required: true,
                    date: true
                },
                datetime: {
                    required: true
                },
                time: {
                    required: true
                },
                select: {
                    required: true,
                    minlength: 2,
                    maxlength: 4
                },
                checkbox: {
                    required: true
                },
                daterange: {
                    required: true
                },
                textarea: {
                    required: true
                },
                markdown: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: '请输入用户名!'
                },
                email: {
                    required: '请输入邮件地址!',
                    email: '请输入正确的邮件地址!'
                },
                date: {
                    required: '请选择日期!',
                    email: '请选择正确的日期!'
                },
                datetime: {
                    required: '请选择日期和时间!'
                },
                time: {
                    required: '请选择时间!'
                },
                select: {
                    required: '请选择下拉菜单!',
                    minlength: '至少选2个选项!',
                    maxlength: '最大选4个选项!'
                },
                checkbox: {
                    required: '请勾选复选框!'
                },
                daterange: {
                    required: '请选择日期范围!',
                    minlength: '请输入正确的邮件地址!'
                },
                textarea: {
                    required: '请输入备注!'
                },
                markdown: {
                    required: '请输入文本!'
                }
            },

            //display error alert on form submit
            invalidHandler: function(event, validator) {
                if (validator.errorList.length > 0) {
                    $(validator.errorList[0].element).focus();
                }
            },

            submitHandler: function (form) {
                form[0].submit(); // submit the form
            }
        });
    };

    var imagesData = [
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD11D',
            fileHbasePath: '20190118174324022_5762_file.png',
            fileName: '2018-05-04_163727.png'
        },
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD12D',
            fileHbasePath: '20190118174327059_6449_file.png',
            fileName: '2018-05-04_163743.png'
        }
    ];
    var filesData = [
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD10D',
            fileHbasePath: "20190118141846160_1593_file.pdf",
            fileName: "20161212195644212_3075_file.pdf"
        },
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD11D',
            fileHbasePath: "20190118141911739_6970_file.doc",
            fileName: "平台样式使用错误问题.doc"
        },
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD11D',
            fileHbasePath:  "20190118141921840_2192_file.xls",
            fileName: "测试电子表格.xls"
        },
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD12D',
            fileHbasePath: "20190118141926862_1874_file.zip",
            fileName: "测试压缩文件.zip"
        },
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD12D',
            fileHbasePath: "20190118141934772_6928_file.jpg",
            fileName: "20161212195644212_3077_file.jpg"
        },
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD12D',
            fileHbasePath: "20190118142008731_7632_file.mpp",
            fileName: "基础平台研发计划-0210-前端.mpp"
        },
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD12D',
            fileHbasePath: "20190118142015864_4432_file.mp3",
            fileName: "测试音频播放.mp3"
        },
        {
            fileId: '7E5CB71C936B4AC28D3F0488933BD12D',
            fileHbasePath: "20190118142019166_3684_file.mp4",
            fileName: "测试视频播放.mp4"
        }
    ];
    var initFileUploader = function () {
        $('#img-uploader').loadImgUpload({
            imagesData: imagesData,
            fileSingleSizeLimit: 15
        });

        $('.file-uploader').loadFileUpload({
            filesData: filesData,
            // isViewModel : true,
            fileNumLimit: 15,
            accept: {
                title:'Files',
                extensions: 'pdf,doc,xls,zip,jpg,mpp,mp3,mp4'
            }
        });

        $('#img-uploader1').loadImgUpload({
            imagesData: imagesData,
            isViewModel : true
        });

        $('.upload-files').initUploadFiles({
            filesData: filesData,
        });
    };

    var doSearch = function () {
        var query = baseTable.getDataSourceQuery();
        query.generalSearch = $('#generalSearch').val();
        query.status = $('#k_form_status').val();
        query.type = $('#k_form_type').val();
        baseTable.setDataSourceQuery(query);
        baseTable.search();
    };
    var doSearch1 = function () {
        var query = scrollTable.getDataSourceQuery();
        query.generalSearch = $('#generalSearch1').val();
        query.status = $('#k_form_status1').val();
        query.type = $('#k_form_type1').val();
        scrollTable.setDataSourceQuery(query);
        scrollTable.search();
    };

    var mergeCelltable = function () {
        var options = {
            $target: $('#merge-table'),
            ajax: '../json/standard/merge-table.json',
            order: [[0, 'asc'], [1, 'asc']],
            rowGroupDataSrc: ['fgs', 'qk'],
            columns: [
                {
                    data: "fgs",
                    title: "公司"
                },
                {
                    data: "qk",
                    title: "所属气矿"
                },
                {
                    data: "地质_zs",
                    title: "工作质量数"
                },
                {
                    data: "地质_fb",
                    title: "已发布数"
                },
                {
                    data: "采气_zs",
                    title: "工作质量数"
                },
                {
                    data: "采气_fb",
                    title: "已发布数"
                },
                {
                    data: "输配_zs",
                    title: "工作质量数"
                },
                {
                    data: "输配_fb",
                    title: "已发布数"
                },
                {
                    data: "自控_zs",
                    title: "工作质量数"
                },
                {
                    data: "自控_fb",
                    title: "已发布数"
                },
                {
                    data: "气田水_zs",
                    title: "工作质量数"
                },
                {
                    data: "气田水_fb",
                    title: "已发布数"
                },
                {
                    data: "脱水_zs",
                    title: "工作质量数"
                },
                {
                    data: "脱水_fb",
                    title: "已发布数"
                },
                {
                    data: "供电_zs",
                    title: "工作质量数"
                },
                {
                    data: "供电_fb",
                    title: "已发布数"

                }
            ]
        };

        tableMergeCell.initMergeCellTable(options);
    };

    return {
        // Init demos
        init: function() {
            eventHandler();
            initSelectPicker();
            initDatePicker();
            initBaseTable();
            initScrollTable();
            initLockedTable();
            initBaseForm();
            initValidation();
            initFileUploader();
            mergeCelltable();
        }
    };
}();

// Class initialization on page load
jQuery(document).ready(function() {
    KStandard.init();
});